package com.yenlien.traceyun.control.dao;

import com.yenlien.traceyun.control.entity.Log;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface LogDao extends BaseJpaDao<Log> {
    List<Log> findByUserNameAndOperation(String userName, String operation);

    List<Log> findByOperation(String operation);

    List<Log> findDistinctUserNameByCreatetimeBetween(Date createtime, Date createtime2);

    List<Log> findCompanyIdDistinctByCreatetimeBetween(Date createtime, Date createtime2);

    List<Log> findByProfessionAndCreatetimeBetween(String profession, Date createtime, Date createtime2);

    @Query(value = "SELECT COUNT(*) FROM t_control_log WHERE company_id in (?1) AND createtime BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW()", nativeQuery = true)
    int getCompActivation(List<String> companyIds);

    @Query(value = "SELECT COUNT(*) FROM t_control_log WHERE company_id = ?1 AND createtime BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW()", nativeQuery = true)
    int getUserActivation(List<String> companyIds);
}
